/* $Id: ShowTableFormat.java,v 1.3 2006/09/15 08:21:42 gigabass Exp $
 *
 * Copyright (c) Guido Ludwig. All rights reserved.
 * Use is subject to license terms.
 */
package de.guidoludwig.jtm.client.shows;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.table.AbstractTableModel;

import com.jgoodies.binding.list.SelectionInList;

import de.guidoludwig.af.AFProperties;
import de.guidoludwig.jtm.domain.Show;

/**
 * Default table format for a table showing a show.
 *
 * @author Guido
 *
 */
public class ShowTableFormat extends AbstractTableModel{

	private static final String LABEL_ARTIST = "editor.show.label.artist";//$NON-NLS-1$
	private static final String LABEL_DATE = "editor.show.label.date";//$NON-NLS-1$

	private static final AFProperties PROPERTIES = new AFProperties(ShowTableFormat.class);

	private static final String[] columnNames = { PROPERTIES.getString(LABEL_ARTIST), PROPERTIES.getString(LABEL_DATE) };

	private final SelectionInList<Show> shows;

	public ShowTableFormat (SelectionInList<Show> a) {
		this.shows = a;
		this.shows.addPropertyChangeListener(SelectionInList.PROPERTYNAME_LIST, new PropertyChangeListener() {

			@Override
			public void propertyChange(PropertyChangeEvent evt) {
				fireTableDataChanged();
			}
		});
	}

	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	@Override
	public String getColumnName(int arg0) {
		return columnNames[arg0];
	}
    @Override
	public Object getValueAt(int row, int column) {
    	Show a = shows.getList().get(row);
    	switch (column) {
		case 0:
			return a.getArtist() == null ? null : a.getArtist().getName();
		case 1:
			return a.getShowDate();
		default:
			throw new IllegalArgumentException("Unknown column " + column);
		}
    }

	@Override
	public int getRowCount() {
		return shows.getSize();
	}

}